﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Components
{
    /// <summary>
    /// HashTable 辅助类
    /// </summary>
    public class HashUtil
    {
        private Hashtable _data;

        public HashUtil(Hashtable hs)
        {
            _data = hs;
        }

        public string GetString(string k)
        {
            return (ExistsKey(k)) ? Validation.ToString(_data[k]) : "";
        }

        public string GetStringNullable(string k)
        {
            return (ExistsKey(k)) ? Validation.ToString(_data[k]) : null;
        }

        public int GetInt(string k)
        {
            return (ExistsKey(k)) ? Validation.ToInt(_data[k]) : 0;
        }

        public int? GetIntNullable(string k)
        {
            if (ExistsKey(k))
                return Validation.ToInt(_data[k]);
            return null;
        }

        public double GetDouble(string k)
        {
            return (ExistsKey(k)) ? Validation.ToDouble(_data[k]) : 0;
        }

        public double? GetDoubleNullable(string k)
        {
            if (ExistsKey(k))
                return Validation.ToDouble(_data[k]);
            return null;
        }

        public bool GetBool(string k)
        {
            return (ExistsKey(k)) ? Validation.ToBool(_data[k]) : false;
        }

        public bool? GetBoolNullable(string k)
        {
            if (ExistsKey(k))
                return Validation.ToBool(_data[k]);
            return null;
        }

        public bool ExistsKey(string k)
        {
            return (null != _data && _data.ContainsKey(k));
        }

    }
}
